from sqlalchemy import ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.core.models.enums import OrderStatus

from .base import TimedBaseModel


class Order(TimedBaseModel):
    __tablename__ = "order"
    __mapper_args__ = {"eager_defaults": True}

    id: Mapped[int] = mapped_column(primary_key=True)
    status: Mapped[OrderStatus] = mapped_column(server_default="created")
    sum: Mapped[float]
    user = relationship("User", back_populates="orders")
    user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))

    def __repr__(self):
        return f"<Order №{self.id} {self.created_at}>"

    def __str__(self):
        return self.__repr__()
